package com.camel.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.camel.base.model.ZsProject;
import com.camel.base.model.ZsSurvey;
import com.camel.base.service.ZsProjectService;
import com.camel.base.service.ZsSurveyService;
import com.camel.core.controller.BaseCommonController;
import com.camel.core.exceptions.CustomException;
import com.camel.core.service.BaseCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;

/**
 * @author camel
 */
@RestController
@RequestMapping("zsProject")
public class ZsProjectController extends BaseCommonController<ZsProject> {

    @Autowired
    private ZsProjectService<ZsProject> service;

    @Autowired
    private ZsSurveyService<ZsSurvey> surveyService;

    @Override
    public BaseCommonService<ZsProject> getiService() {
        return service;
    }

    @Override
    public boolean deleteAble(Serializable id) {
        super.deleteAble(id);
        if(surveyService.count(new QueryWrapper<ZsSurvey>().eq("project_id", id)) > 0) {
            throw new CustomException("删除失败: 项目下存在未删除的问卷!");
        }
        return true;
    }

    @Override
    public String getMouduleName() {
        return "项目";
    }
}
